<?php

    /**
     * Class autoload
     *
     * @param       string          $class
     * @return      void
     */
    function __autoload($class)
    {
        if (empty($class)) {
            return;
        }

        if (substr($class, 0, 2) == 'Db' || substr($class, 0, 6) == 'BaseDb') {
            Doctrine::autoload($class);
        } else {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($class);
        }
    }

    /**
     * Translator function
     *
     * @param       string          $key : the index of the text to translate
     * @param       array|string    $args : arguments to apply to the localized string with sprintf
     * @param       string          $locale : the language code. If null, use the default language
     * @return      string          the localized string
     */
    function __($key, $args = null, $locale = null)
    {
        return Core_Locale::getInstance()->translate($key, $args, $locale);
    }

	/**
	 * Converts to HTML within the specified charset
	 *
	 * @param      string|array|object     $data : the text to encode
	 * @return	   string                  the HTML encoded version
	 */
	function toHtmlEntities(&$data)
	{
		$registry	= Zend_Registry::getInstance();
		$charset	= $registry['config']->view->encoding;

		if (is_array($data)) {
			foreach ($data as $key => $value) {
                $data[$key] = (is_bool($value) || is_null($value)) ? $value : toHtmlEntities($value);
			}
//		} else if (is_object($data)) {
//			foreach ($data as $property) {
//                $data[$key] = (is_bool($value) || is_null($value)) ? $value : toHtmlEntities($value);
//				$property = toHtmlEntities($value);
//			}
		} else {
			$data = htmlentities($data, ENT_QUOTES, $charset);
		}

		return $data;
	}